import { Controller } from "egg";

export default class UserController extends Controller {
  // 获取所有用户的基本信息（含ID、用户名、状态）
  public async listAll() {
    const { ctx, app } = this;
    const { models } = app as any;

    try {
      const users = await models.User.findAll({
        attributes: ["id", "username", "status", "created_at"],
        order: [["created_at", "DESC"]]
      });

      ctx.body = { success: true, data: users };
    } catch (error) {
      ctx.logger.error("获取用户列表失败:", error);
      ctx.status = 500;
      ctx.body = { success: false, code: "GET_USERS_ERROR", message: "获取用户列表失败" };
    }
  }
}


